<template>
  <view v-if="!isLoading" class="container">
    <u-card title="今日">
		<view class="" slot="body">
			<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
				<view class="my-asset">
				  <view class="asset-left flex-box dis-flex flex-x-center">
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewToday.orderTotalPrice }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>销售额</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewToday.orderTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>支付订单数</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewToday.goodsTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>商品数量</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewToday.consumeUsers }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>消费人数</text>
					  </view>
					</view>
				  </view>
				</view>
			</view>
		</view>
	</u-card>
		
	<u-card title="本月">
		<view class="" slot="body">
			<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
				<view class="my-asset">
				  <view class="asset-left flex-box dis-flex flex-x-center">
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewMonth.orderTotalPrice }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>销售额</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewMonth.orderTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>支付订单数</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewMonth.goodsTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>商品数量</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewMonth.consumeUsers }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>消费人数</text>
					  </view>
					</view>
				  </view>
				</view>
			</view>
		</view>
	</u-card>
	
	<u-card title="本年度">
		<view class="" slot="body">
			<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
				<view class="my-asset">
				  <view class="asset-left flex-box dis-flex flex-x-center">
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewYear.orderTotalPrice }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>销售额</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewYear.orderTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>支付订单数</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewYear.goodsTotal }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>商品数量</text>
					  </view>
					</view>
					<view class="asset-left-item">
					  <view class="item-value dis-flex flex-x-center">
						<text>{{ storeData.overviewYear.consumeUsers }}</text>
					  </view>
					  <view class="item-name dis-flex flex-x-center">
						<text>消费人数</text>
					  </view>
					</view>
				  </view>
				</view>
			</view>
		</view>
	</u-card>
	
  </view>
</template>

<script>
  import shop from '@/shop'
  import { setCartTabBadge } from '@/utils-shop/app'
  import * as StoreApi from '@/apishop/store'
  import { checkLogin } from '@/utils-shop/app'

  export default {
    data() {
      return {
        // 当前运行的终端 (此处并不冗余,因为微信小程序端view层无法直接读取$platform)
        $platform: this.$platform,
        // 正在加载
        isLoading: true,
        // 是否已登录
        isLogin: false,
        // 账户资产
        storeData: {}
      }
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow(options) {
      this.onRefreshPage()
    },

    methods: {

      // 刷新页面
      onRefreshPage() {
        // 更新购物车角标
        // setCartTabBadge()
        // 判断是否已登录
        this.isLogin = checkLogin()
        // 获取页面数据
        this.getPageData()
      },

      // 获取页面数据
      getPageData(callback) {
        const app = this
        app.isLoading = true
        Promise.all([app.getStoreData()])
          .then(result => {
			  console.log(result)
            app.isLoading = false
            // 执行回调函数
            callback && callback()
          })
          .catch(err => {
            console.log('catch', err)
          })
		// initData()
      },

      // 获取当前店铺的数据
      getStoreData() {
        const app = this
        return new Promise((resolve, reject) => {
          !app.isLogin ? resolve(null) : StoreApi.statistics()
            .then(result => {
              app.storeData = result.data.data
              resolve(app.storeData)
            })
            .catch(err => {
              if (err.result && err.result.status == 401) {
                app.isLogin = false
                resolve(null)
              } else {
                reject(err)
              }
            })
        })
      },
	  
    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh() {
      // 获取首页数据
      this.getPageData(() => {
        uni.stopPullDownRefresh()
      })
    },


  }
</script>

<style lang="scss" scoped>
  // 页面头部
  .main-header {
    background-color: #fff;
    // background-image: url('/static/background/user-header.png');
    position: relative;
    width: 100%;
    height: 280rpx;
    background-size: 100% 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    // padding-top: 40rpx;
    padding-left: 30rpx;

    .bg-image {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 0;
    }

    .user-info {
      display: flex;
      height: 100rpx;
      z-index: 1;

      .user-avatar .image {
        display: block;
        width: 100rpx;
        height: 100rpx;
        border-radius: 50%;
      }

      .user-content {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-left: 30rpx;
        color: #c59a46;

        .nick-name {
          font-size: 32rpx;
          font-weight: bold;
        }

        .mobile {
          margin-top: 15rpx;
          font-size: 26rpx;
        }

        .user-grade {
          display: flex;
          align-items: center;
          background: #3c3c3c;
          margin-top: 12rpx;
          border-radius: 10rpx;
          padding: 4rpx 12rpx;

          .user-grade_icon .image {
            display: block;
            width: 32rpx;
            height: 32rpx;
          }

          .user-grade_name {
            margin-left: 5rpx;
            font-size: 24rpx;
            color: #EEE0C3;
          }

        }

        .login-tips {
          margin-top: 12rpx;
          font-size: 28rpx;
        }

      }
    }
  }

  // 我的钱包
  .my-asset {
    display: flex;
    background: #fff;
    padding: 40rpx 0;

    .asset-right {
      width: 200rpx;
      border-left: 1rpx solid #eee;
    }

    .asset-right-item {
      text-align: center;
      color: #545454;

      .item-icon {
        font-size: 40rpx;
      }

      .item-name {
        margin-top: 10rpx;
      }

      .item-name text {
        font-size: 25rpx;
      }

    }

    .asset-left-item {
      text-align: center;
      color: #666;
      padding: 0 30rpx;

      .item-value {
        font-size: 32rpx;
        color: red;
      }

      .item-name {
        margin-top: 6rpx;
      }

      .item-name {
        font-size: 25rpx;
      }
    }

  }
</style>
